package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.entity.Dish;
import com.chixing.mapper.DishMapper;
import com.chixing.service.IDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Yebken.
 * @since 2025-06-25
 */

@Service
public class DishServiceImpl implements IDishService {

    @Autowired
    private DishMapper dishMapper; //持久层

    @Override
    public List<Dish> getAll() {
        List<Dish> dishList = dishMapper.selectList(null);
        return dishList;
    }

    @Override
    public Dish getById(Integer dishId) {
        //执行SQL语句 select * form dish where dish_id = 2
        Dish dish = dishMapper.selectById(dishId);
        return dish;
    }

    @Override
    public List<Dish> getByType(Integer typeId) {
        //select * from dish where type_id = 2
        QueryWrapper<Dish> wrapper = new QueryWrapper<>();
        wrapper.eq("type_id",typeId);
        List<Dish> dishList = dishMapper.selectList(wrapper);
        return dishList;
    }

    @Override
    public List<Dish> getByName(String dishName) {
        QueryWrapper<Dish> wrapper = new QueryWrapper<>();
        wrapper.like("dish_name", "%" + dishName + "%");
        List<Dish> dishList = dishMapper.selectList(wrapper);
        return dishList;
    }
}
